<html>
<head>
    <meta charset=UTF-8>
    <meta name=viewport content="width=device-width,initial-scale=1,shrink-to-fit=no">
    <meta http-equiv=X-UA-Compatible content="ie=edge">
    <title>注册</title></head>
<body>
<div class=logn_box>
    <div class=logn_top><img src="/Public/default.jpg"/>
        <p>欢迎使用mou收银台</p></div>
    <div class=logn_dl>
        <ul>
            <li class=rech_1><input style="background:url('/Public/Home/js/images/re_1.png') no-repeat 10px center;background-size: 30px;" id="phone" placeholder=请输入手机号 type=text/></li>
            <li class=rech_2><input style="background:url('/Public/Home/js/images/re_2.png') no-repeat 10px center;background-size: 30px;"  id=code placeholder=请输入验证码 type=password/> <a id=obtain>发送验证码</a></li>
            <li class=rech_3><input style="background:url('/Public/Home/js/images/re_3.png') no-repeat 10px center;background-size: 30px;"  id=password placeholder=请输入密码 type=text/></li>
            <!--<li class=rech_4><input id=tjcode placeholder=请输入推荐码 type=text/></li>-->

        </ul>
    </div>
    <button class="zm-btndanger" id="index_logn">注册</button>
</div>
<script type="text/javascript" src="__STATIC__/jquery.min.js"></script>
<script type="text/javascript" src="/Public/Home/js/app.js"></script>
<script type="text/javascript" src="/Public/Home/js/nuox.js"></script>
<script type="text/javascript" src="/Public/static/layer/layer.js"></script>

<script>

    //发送验证码
    $('.rech_2').on('click', '#obtain', function () {
        var $t = $(this);
        var phone = $("#phone").val();
        var time;

        if (phone == "") {
            return false;
        }
        if (!rules_phone.exec(phone)) {
            alert("手机号格式错误!");
        }

        $.post(paraurl + 'home/common/sendSms?tm=' + tm, {
            mobile: phone,
            event: "register"
        }, function (data) {
            var data = JSON.parse(data);
            if (data.code == 1) {
                var t = 60;
                if ($t.text() != "发送验证码") {
                    return false;
                }
                time = setInterval(function () {
                    if (t == 0) {
                        $t.text("发送验证码");
                        clearInterval(time);
                    } else {
                        t = t - 1;
                        $t.text("重新发送" + t + "S");
                    }
                }, 1000);
            }
        })
    })

    //提交注册
    $('#index_logn').click(function(){
        var tg_num = $.getUrlParam('tg_num');
        var phone = $("#phone").val();
        var code = $('#code').val();
        var password = $('#password').val();

        console.log('tg_num:'+tg_num);
        if(phone && tg_num && code && password){
            $.post(paraurl + 'home/user/register?tm=' + tm, {
                phone: phone,
                code: code,
                password: password,
                tg_num: tg_num
            }, function (data) {
                var data = JSON.parse(data);
                if (data.code == 1) {
                    layer.msg('注册成功,请下载app登录！',{time:5*1000});
                }else{
                    layer.msg('注册失败，请重新再试');
                }
            })
        }else{
            if(!tg_num){
                layer.msg('推荐码不能为空！',{icon:5});
            }
            if(!phone){
                layer.msg('手机号码不能为空！',{icon:5});
            }
            if(!code){
                layer.msg('手机验证码不能为空！',{icon:5});
            }
            if(!password){
                layer.msg('密码不能为空！',{icon:5});
            }


        }


    });

    (function ($) {
        $.getUrlParam = function (name) {
            var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
            var r = window.location.search.substr(1).match(reg);
            if (r != null) return unescape(r[2]); return null;
        }
    })(jQuery);

</script>
</body>
</html>